<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="合同申请编号" prop="contAppNum">
      <el-input v-model="dataForm.contAppNum" placeholder="合同申请编号"></el-input>
    </el-form-item>
    <el-form-item label="报价份数" prop="statQuote">
      <el-input v-model="dataForm.statQuote" placeholder="报价份数"></el-input>
    </el-form-item>
    <el-form-item label="最高报价" prop="topQuote">
      <el-input v-model="dataForm.topQuote" placeholder="最高报价"></el-input>
    </el-form-item>
    <el-form-item label="最低报价" prop="lowQuote">
      <el-input v-model="dataForm.lowQuote" placeholder="最低报价"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="allSumPrice">
      <el-input v-model="dataForm.allSumPrice" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="合同申请备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="合同申请备注"></el-input>
    </el-form-item>
<!--    <el-form-item label="编制人序号" prop="authorId">-->
<!--      <el-input v-model="dataForm.authorId" placeholder="编制人序号"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="编制人" prop="author">-->
<!--      <el-input v-model="dataForm.author" placeholder="编制人"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="计划员序号" prop="planerId">-->
<!--      <el-input v-model="dataForm.planerId" placeholder="计划员序号"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="计划员" prop="planer">-->
<!--      <el-input v-model="dataForm.planer" placeholder="计划员"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="计划员是否同意" prop="planAgree">-->
<!--      <el-input v-model="dataForm.planAgree" placeholder="计划员是否同意"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="计划员审核意见" prop="planOpinion">-->
<!--      <el-input v-model="dataForm.planOpinion" placeholder="计划员审核意见"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="计划员审批时间" prop="planDate">-->
<!--      <el-input v-model="dataForm.planDate" placeholder="计划员审批时间"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="部长序号" prop="leaderId">-->
<!--      <el-input v-model="dataForm.leaderId" placeholder="部长序号"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="部长" prop="leader">-->
<!--      <el-input v-model="dataForm.leader" placeholder="部长"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="部长是否同意" prop="leadAgree">-->
<!--      <el-input v-model="dataForm.leadAgree" placeholder="部长是否同意"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="部长审核意见" prop="leadOpinion">-->
<!--      <el-input v-model="dataForm.leadOpinion" placeholder="部长审核意见"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="部长审核时间" prop="leadDate">-->
<!--      <el-input v-model="dataForm.leadDate" placeholder="部长审核时间"></el-input>-->
<!--    </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          contAppNum: '',
          statQuote: '',
          topQuote: '',
          lowQuote: '',
          allSumPrice: '',
          remark: '',
          authorId: '',
          author: '',
          planerId: '',
          planer: '',
          planAgree: '',
          planOpinion: '',
          planDate: '',
          leaderId: '',
          leader: '',
          leadAgree: '',
          leadOpinion: '',
          leadDate: ''
        },
        dataRule: {
          contAppNum: [
            { required: true, message: '合同申请编号不能为空', trigger: 'blur' }
          ],
          statQuote: [
            { required: true, message: '报价份数不能为空', trigger: 'blur' }
          ],
          topQuote: [
            { required: true, message: '最高报价不能为空', trigger: 'blur' }
          ],
          lowQuote: [
            { required: true, message: '最低报价不能为空', trigger: 'blur' }
          ],
          allSumPrice: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '合同申请备注不能为空', trigger: 'blur' }
          ],
          authorId: [
            { required: true, message: '编制人序号不能为空', trigger: 'blur' }
          ],
          author: [
            { required: true, message: '编制人不能为空', trigger: 'blur' }
          ],
          planerId: [
            { required: true, message: '计划员序号不能为空', trigger: 'blur' }
          ],
          planer: [
            { required: true, message: '计划员不能为空', trigger: 'blur' }
          ],
          planAgree: [
            { required: true, message: '计划员是否同意不能为空', trigger: 'blur' }
          ],
          planOpinion: [
            { required: true, message: '计划员审核意见不能为空', trigger: 'blur' }
          ],
          planDate: [
            { required: true, message: '计划员审批时间不能为空', trigger: 'blur' }
          ],
          leaderId: [
            { required: true, message: '部长序号不能为空', trigger: 'blur' }
          ],
          leader: [
            { required: true, message: '部长不能为空', trigger: 'blur' }
          ],
          leadAgree: [
            { required: true, message: '部长是否同意不能为空', trigger: 'blur' }
          ],
          leadOpinion: [
            { required: true, message: '部长审核意见不能为空', trigger: 'blur' }
          ],
          leadDate: [
            { required: true, message: '部长审核时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/purchase/contractapply/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then((data) => {
              if (data && data.code === 200) {
                this.dataForm.contAppNum = data.contractApply.contAppNum
                this.dataForm.statQuote = data.contractApply.statQuote
                this.dataForm.topQuote = data.contractApply.topQuote
                this.dataForm.lowQuote = data.contractApply.lowQuote
                this.dataForm.allSumPrice = data.contractApply.allSumPrice
                this.dataForm.remark = data.contractApply.remark
                this.dataForm.authorId = data.contractApply.authorId
                this.dataForm.author = data.contractApply.author
                this.dataForm.planerId = data.contractApply.planerId
                this.dataForm.planer = data.contractApply.planer
                this.dataForm.planAgree = data.contractApply.planAgree
                this.dataForm.planOpinion = data.contractApply.planOpinion
                this.dataForm.planDate = data.contractApply.planDate
                this.dataForm.leaderId = data.contractApply.leaderId
                this.dataForm.leader = data.contractApply.leader
                this.dataForm.leadAgree = data.contractApply.leadAgree
                this.dataForm.leadOpinion = data.contractApply.leadOpinion
                this.dataForm.leadDate = data.contractApply.leadDate
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/purchase/contractapply/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'contAppNum': this.dataForm.contAppNum,
                'statQuote': this.dataForm.statQuote,
                'topQuote': this.dataForm.topQuote,
                'lowQuote': this.dataForm.lowQuote,
                'allSumPrice': this.dataForm.allSumPrice,
                'remark': this.dataForm.remark,
                'status':'C001-110',
                'authorId': '',
                'author': '',
                'planerId': '',
                'planer': '',
                'planAgree': '',
                'planOpinion': '',
                'planDate': '',
                'leaderId': '',
                'leader': '',
                'leadAgree': '',
                'leadOpinion': '',
                'leadDate': ''
              })
            }).then((data) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
